package configlogic

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/config"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"
	"github.com/zeromicro/go-zero/core/logx"
)

type GetConfigInOutListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
	repo *config.InoutModel
}

func NewGetConfigInOutListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetConfigInOutListLogic {
	return &GetConfigInOutListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
		repo:   config.NewInoutModel(ctx, svcCtx.Db),
	}
}

// ------------------余额变动类型 ------------------
// GetConfigInOutList 获取余额变动类型配置列表
func (l *GetConfigInOutListLogic) GetConfigInOutList(in *rpc.GetConfigInOutListRq) (*rpc.GetConfigInOutListReps, error) {
	result, err := l.repo.All()
	if err != nil {
		return nil, err
	}
	var list = make([]*rpc.ConfigInOutList, 0)
	for _, row := range result {
		list = append(list, &rpc.ConfigInOutList{
			Id:      row.Id,
			TypeId:  row.TypeId,
			Name:    row.Name,
			Value:   row.Value,
			TagType: int32(row.TagType),
			Remark:  row.Remark,
		})
	}
	return &rpc.GetConfigInOutListReps{List: list}, nil
}
